import scrapy
from scrapy.http import Request
import json

class HeroSpider(scrapy.Spider):
    name = 'hero'
    allowed_domains = ['yjwujian.cn']
    start_urls = ['https://yjwujian.res.netease.com/pc/zt/20220424170701103/js/Hero_5f194154.js']


    def parse(self, response):
        hero_urls = response.xpath('//div[@class="heros-container"]//@href').getall()
        pre_url = ""
        hero_names = response.xpath('//div[@class="name centerX"]/span[1]').getall()
        for hero_u,hero_n in zip(hero_urls,hero_names):
            hero_url = pre_url+hero_u
            hero_name = hero_n
            yield Request(hero_url, hero_name, callback=self.hero_parse)

    def hero_parse(self, response):
        hero_pic_url1 = response.xpath('//div[@class="illustration-container centerX"]/div[1]/@style').get()
        hero_pic_url2 = response.xpath('//div[@class="illustration-container centerX"]/div[2]/@style').get()
        hero_pic_url3 = response.xpath('//div[@class="illustration-container centerX"]/div[3]/@style').get()
        for i in range(1,4):
            image_urls = response.xpath(f'//div[@class="illustration-container centerX"]/div[{i}]/@style').get()
            yield {
                'image_urls': image_urls,
                'hero_name': response.get('hero_name')
            }
        hero_story = response.xpath('//div[@class="text-container centerX"]/div[@class="single-text"]').get()
